<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Group extends Model
{
    use HasFactory;

    protected $fillable = ['name','open_day','open_hour','order_type','time_span'];

    public function rooms(){
        return $this->hasMany(Room::class);
    }

    /**
     * @param $data
     * @param null $id
     */
    public static function dataSave($data, $id = null ): Group
    {
        if($id){
            unset($data['created_at']);
            unset($data['updated_at']);
            self::query()->where('id',$id)->update($data);
            $group = self::query()->find($id);
        }else{
            $group = self::create($data);
        }
        return $group;
    }
}
